package com.hileto.inf.modules.user;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hileto.inf.models.Student;
import com.hileto.inf.utils.spring.SpringJdbcProxy;

@Service
@Transactional
public class TestService {
	@Autowired
	private SpringJdbcProxy springJdbcProxy;
	
//	@Autowired
//	private BBService bbService;

	public void save(Student student) {
		springJdbcProxy.saveObject(student);
	}

	public void update(Student student) {
		springJdbcProxy.updateObject(student);
	}

	public List<Student> queryUser() {
		List<Student> userLst = null;
		userLst = springJdbcProxy.queryForList(Student.class);
		return userLst;
	}

	public List<String> getMessage(String appKey, String sessionKey,
			Integer msgSize) {
		return new ArrayList<String>();
	}

	public void update() {
		springJdbcProxy.getJdbcTemplate().update(
				"insert into student(name,age,sex) values('"+UUID.randomUUID().toString()+"',19,2)",
				new PreparedStatementSetter() {
					@Override
					public void setValues(PreparedStatement arg0)
							throws SQLException {
						System.out.println("TestService : "
								+ arg0.getConnection());
					}
				});
		System.out.println(1/0);
	}
}
